package com.heima.wemedia.controller;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemeda.dto.WmNewsDto;
import com.heima.model.wemeda.dto.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/submit")
    public ResponseResult addNews(@RequestBody WmNewsDto wmNewsDto) {
        return wmNewsService.addNewsAndNewsMaterial(wmNewsDto);
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto wmNewsDto) {
        return wmNewsService.queryPage(wmNewsDto);
    }

    @GetMapping("/one/{id}")
    public  ResponseResult queryById(@PathVariable Long id){
       return wmNewsService.queryById(id);
    }

    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Long id){
        return wmNewsService.deleteById(id);
    }
}
